#ifndef Buffer_h
#define Buffer_h

#include "String.h"


class Buffer_T
{
private:
	unsigned char * _pb;
	unsigned int _len;
	unsigned int _max;
	bool _isSymlink;

	static unsigned char pbUTF8_AND[6][6];
	static unsigned char pbUTF8_CMP[6][6];

private:
	bool IsUtf8Encoded
	(
		unsigned char pbA[], 
		unsigned char pbB[], 
		unsigned char pbC[], 
		unsigned char pbD[], 
		char cMax
	);

// Ctor / Dtor
public:
	Buffer_T();
	Buffer_T(unsigned char * pb, unsigned int len);
	Buffer_T(const char * sz);
	Buffer_T(const String_T & str);
	Buffer_T(const Buffer_T & buf);
	Buffer_T & operator=(const Buffer_T & buffer);
	~Buffer_T();

public:
	unsigned char operator[](unsigned int ix) const	{ return _pb[ix];	};
	unsigned int Length() const						{ return _len;		};
	unsigned int Max() const						{ return _max;		};
	unsigned char * Ptr() const						{ return _pb;		};

	bool Equals(const Buffer_T & buf, bool isCaseSensitive) const;
	bool StartsWith(const Buffer_T & buf, bool isCaseSensitive) const;
	unsigned int IndexOf(const Buffer_T & buf) const;
	unsigned int IndexOf(const Buffer_T & buf, unsigned int startIndex) const;
	unsigned int LastIndexOf(const Buffer_T & buf) const;
	Buffer_T SubBuffer(unsigned int startIndex) const;
	Buffer_T SubBuffer(unsigned int startIndex, unsigned int length) const;

	bool IsNumeric() const;
	unsigned int ToNumber() const;
	String_T ToString() const { return String_T((char *)_pb, _len); }
	const char * ToString(char *, unsigned int) const;

public:
	void Create(unsigned int max);
	void Concat(const Buffer_T & buf);
	void Decode();
	void Free();
};

#endif //Buffer_h